package com.boot2.core.web;

import com.alibaba.fastjson.JSONObject;
import com.boot2.core.constant.HttpConstant;
import lombok.SneakyThrows;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * 
 * @ClassName: AbstractBusinessInterceptor
 * @description: 全局业务拦截器
 * @author zhangweilin
 * @date 2017年12月25日 下午1:53:26
 *
 */
public abstract class AbstractBusinessInterceptor implements HandlerInterceptor {

	@Deprecated
	public static final String modelBasePackageName = "com.boot2.arkiot.model";

	@SneakyThrows
	public void outPrintJson(HttpServletResponse response,Object obj) {
		response.setContentType(HttpConstant.contentTypeJsonUTF8);
		PrintWriter writer = response.getWriter();
		writer.write(JSONObject.toJSONString(obj));
		writer.flush();
		writer.close();
	}

	@SneakyThrows
	public void outPrintJson(HttpServletResponse response,String json) {
		response.setContentType(HttpConstant.contentTypeJsonUTF8);
		PrintWriter writer = response.getWriter();
		writer.write(json);
		writer.flush();
		writer.close();
	}



}
